package com.jt.rabbitmq.direct;

import com.jt.utils.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/*路由模式*/
public class Prudocter {
    private static final String exchangeName = "direct——exchange";
    private static final String QUEUE_NAME1 = "direct-test1";
    private static final String QUEUE_NAME2 = "direct-test2";
    private static final String QUEUE_NAME3 = "direct-test3";

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionUtil connectionUtil = new ConnectionUtil();
        Connection connection = connectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT, true, false, false, null);
        /*创建3个队列*/
        channel.queueDeclare(QUEUE_NAME1, true, false, false, null);
        channel.queueDeclare(QUEUE_NAME2, true, false, false, null);
        channel.queueDeclare(QUEUE_NAME3, true, false, false, null);
        channel.queueBind(QUEUE_NAME1,exchangeName,"one");
        channel.queueBind(QUEUE_NAME2,exchangeName,"two");
        channel.queueBind(QUEUE_NAME3,exchangeName,"three");
        String body="路由交换机one测试";
        channel.basicPublish(exchangeName,"one",null,body.getBytes());
        channel.close();
        connection.close();
    }
}
